home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
8bitfiles.net/archives
/
archives.tar
/
archives
/
compuserve-file-archive
/
09 Application Software
/
PI.BIN
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2019-04-13
|
4KB
|
128 lines
10 POKE55,.:POKE56,160:CLR:S=16:T=9:V=1:W=V:F=48:Z$=CHR$(.):GOSUB200:PRINT"[147][142]"
15 PRINT"ENTER NUMBER OF HEXADECIMAL"
17 PRINT"PLACES DESIRED.":PRINT" [145]":PRINT"9[145]"
20 INPUTN:IFN<3ORN>210THENPRINT"OUT OF RANGE":GOTO15
25 PRINT"[147]CALCULATING (THIS WILL TAKE A WHILE)...":TI$="000000":PRINT"TIME = ";
30 GOSUB400:PRINT"PI =":PRINT"AND":PRINT"PI ="
35 H$="":FORI=VTON+4:H$=H$+CHR$(2):NEXT
40 K$="":FORI=VTON+3:K$=K$+Z$:NEXT:FORI=VTON+3:GOSUB900:NEXT
45 P=ASC(RIGHT$(H$,1)+Z$)+S*ASC(RIGHT$(H$,2)+Z$)+N+3
50 IFRIGHT$(H$,4)=CHR$(7)THENIFRIGHT$(H$,5)=CHR$(15)THENIFP>255THENN=N+V:GOTO30
55 Q=ASC(RIGHT$(H$,4)+Z$):R=ASC(RIGHT$(H$,5)+Z$)-(Q>7):IFR=STHENR=.
60 H$=LEFT$(H$,N-V)+CHR$(R):H=N-2:IFRORQ<8THEN80
65 R=ASC(MID$(H$,H+V)+Z$)+V:IFR=STHENR=.
70 H$=LEFT$(H$,H)+CHR$(R)+LEFT$(K$,W):IFRTHEN80
75 H=H-V:W=W+V:GOTO65
80 GOSUB500:PRINT"$3.";J$:PRINT"AT ";:GOSUB400
85 M=INT(N*1.2042)+V:REM LOG(16)/LOG(10) = 1.2041+
90 FORI=VTOM:N$=N$+"0":NEXT:D$=N$+"00"
95 GOSUB600:Q=ASC(RIGHT$(D$,3)):P=ASC(RIGHT$(D$,4))-(Q>52):IFP=58THENP=48
100 W$=LEFT$(D$,M-4)+CHR$(P):H=M-5:W=V:IFP<>48ORQ<53THEN120
105 R=ASC(MID$(W$,H+V))+V:IFR=58THENR=48
110 W$=LEFT$(W$,H)+CHR$(R)+LEFT$(N$,W):IFR>48THEN120
115 H=H-V:W=W+V:GOTO105
120 PRINT"3.";W$:PRINT"AT ";:GOSUB400:END
200 REM DOCUMENTATION
205 Q$=CHR$(34):PRINT"[147][142] INF"
210 PRINT" [175][175][175]"
215 PRINT" [205]
220 [153]"(null) = (null) 16^-I (4/(8I+1)-2/(8I+4)"
225 [153]" (null) -1/(8I+5)-1/(8I+6))
230 PRINT" [206]
235 [153]" USRUSRUSR
240 PRINT" I=0
245 [141]996
250 [153]"LOAD (null)HE FORMULA ON THE PRECEDING PAGE"
255 [153]"APPEARED IN THE (null)CTOBER 28, 1995 ISSUE"
260 [153]"OF ";Q$;"(null)LENRIGHT$VAL(null)LENVAL (null)VAL(null)(null)";Q$;". (null)HE NEW METHOD OF"
265 [153]"CALCULATING PI WAS CREDITED TO (null)ETER PEEK."
270 [153]"PEEKORWEIN, (null)IMON (null)LOUFFE, AND THEIR"
275 [153]"COWORKERS AT (null)IMON ASCRASER (null)NIVERSITY IN"
280 [153]"PEEKURNABY, PEEKRITISH LENOLUMBIA. (null)HE FINDING"
285 [153]"WAS ANNOUNCED IN AN RIGHT$NTERNET POSTING IN"
290 [153]"EARLY (null)CTOBER. ASCOR MORE INFORMATION,"
295 [153]"CHECK THE (null)ORLD (null)IDE (null)EB SITE AT THIS"
300 [153]"ADDRESS:"
305 [153]"HTTP://WWW.CECM.SFU.CA/(null)PBORWEIN/"
310 [153]"(null)INCE THE FORMULA CALCULATES THE"
315 [153]"COEFFICIENTS OF 16^-RIGHT$ IN THE INFINITE"
320 [153]"SERIES, TRUNCATING AND ROUNDING-OFF ARE"
325 [153]"GREATLY SIMPLIFIED IF THE HEXADECIMAL"
327 [153]"FORM IS USED FOR THE CALCULATION."
330 [153]" (null)HIS PROGRAM, FOR THE LENOMMODORE-64,
335 PRINT"CALCULATES PI IN HEXADECIMAL, FOR AN [206]"
340 PRINT"(2 < [206] < 211) THAT IS ENTERED BY THE"
342 GOSUB997
345 PRINT"[147]USER. [212]RUNCATION IS TO [206]+4 PLACES;"
350 PRINT"ROUNDING-OFF TO [206] PLACES. [201]N THE"
355 PRINT"SPECIAL CASES OF THE LAST FOUR PLACES"
360 PRINT"BEING FROM 7[198][198][196] - [206] TO 7[198][198][198], SINCE FROM"
365 PRINT"0 TO [206]+3 IS SUBTRACTED BY THE TRUNCATION";
370 PRINT"PROCESS, THE 7 CAN ACTUALLY BE AN 8."
375 PRINT"[212]HEREFORE ROUNDING-OFF TO [206] PLACES IS"
380 PRINT"IMPOSSIBLE, AND THE PROGRAM RECALCULATES";
385 PRINT"FOR [206]+1. [196]ISPLAY IS IN BOTH HEX AND"
390 PRINT"DECIMAL. [196]ON'T ENTER AN [206] > 99, UNLESS"
395 PRINT"YOU ARE AN ELEPHANT, A TURTLE, OR ARE"
396 PRINT"SERVING A LIFE SENTENCE."
397 PRINT" [212]HIS PROGRAM IS CONTRIBUTED TO THE"
398 PRINT"[208]UBLIC [196]OMAIN. [202]OHN [201]ANNETTA"
399 GOSUB997
400 REM FORMAT AND PRINT TI$
405 T$=TI$:PRINTLEFT$(T$,2)+":"+MID$(T$,3,2)+":"+RIGHT$(T$,2)
410 RETURN
500 REM CONVERT HEXADIGITS TO ASCII CHARACTERS
505 J$="":FORI=VTOLEN(H$):P=ASC(MID$(H$,I)+Z$):IFP>TTHENP=P+7
510 J$=J$+CHR$(P+F):NEXT:RETURN
600 REM CONVERT HEXADIGITS TO DECIMAL ASCII CHARACTERS
605 FORI=NTOVSTEP-V:X=ASC(MID$(H$,I))
610 Y=INT(X/10):IFYTHENX$=CHR$(V+F)+CHR$(X+38):GOTO620
615 X$="0"+CHR$(X+F)
620 D$=X$+RIGHT$(D$,M):U$="":FORJ=2TOM+2:X$=LEFT$(D$,J)
625 X=INT(VAL(X$)/S):U$=U$+CHR$(X+F)
630 X$=STR$(X*S):IFLEN(X$)=4THENX$=RIGHT$(X$,3):GOTO645
635 IFLEN(X$)=3THENX$="0"+RIGHT$(X$,2):GOTO645
640 X$="000"
645 IFJ=2THENV$=RIGHT$(X$,2)+"0":GOTO660
650 IFJ=3THENV$=X$:GOTO660
655 V$=LEFT$(N$,J-3)+X$
660 IFJ<M+2THENV$=V$+LEFT$(N$,M+2-J)
665 C=.:T$="":FORK=M+2TOVSTEP-V
670 P=ASC(MID$(D$,K)+Z$)-ASC(MID$(V$,K)+Z$)-C:C=.:IFP<.THENP=P+10:C=1
675 T$=CHR$(P+F)+T$:NEXT:D$=T$:NEXT:D$="0"+U$:NEXT:D$=RIGHT$(D$,M)
680 RETURN
700 REM SUBTRACT I$ FROM H$ TO PRODUCE H$
705 U$="":C=.:FORK=N+4TOVSTEP-V
710 P=ASC(MID$(H$,K)+Z$)-ASC(MID$(I$,K)+Z$)-C
715 C=.:IFP<.THENC=V:P=P+S
720 U$=CHR$(P)+U$:NEXT:H$=U$
725 RETURN
800 REM ADD I$ TO H$ TO PRODUCE H$
805 U$="":C=.:FORK=N+4TOVSTEP-V
810 P=ASC(MID$(H$,K)+Z$)+ASC(MID$(I$,K)+Z$)+C
815 C=.:IFP>=STHENC=V:P=P-S
820 U$=CHR$(P)+U$:NEXT:H$=U$
825 RETURN
900 REM USE FORMULA TO CALCULATE PI
905 A=4:B=8*I+1
910 I$="":FORJ=ITON+3:C=INT(S*A/B):I$=I$+CHR$(C):A=S*A-B*C:NEXT
915 I$=LEFT$(K$,I)+I$
920 GOSUB800
925 A=2:B=8*I+4
930 I$="":FORJ=ITON+3:C=INT(S*A/B):I$=I$+CHR$(C):A=S*A-B*C:NEXT
935 I$=LEFT$(K$,I)+I$
940 GOSUB700
945 A=1:B=8*I+5
950 I$="":FORJ=ITON+3:C=INT(S*A/B):I$=I$+CHR$(C):A=S*A-B*C:NEXT
955 I$=LEFT$(K$,I)+I$
960 GOSUB700
965 A=1:B=8*I+6
970 I$="":FORJ=ITON+3:C=INT(S*A/B):I$=I$+CHR$(C):A=S*A-B*C:NEXT
975 I$=LEFT$(K$,I)+I$
980 GOSUB700
985 RETURN
996 PRINT" [PRESS RETURN][146]";:GOTO998
997 PRINT" [[208][210][197][211][211] [210][197][212][213][210][206]][146]";
998 GETA$:IFA$=CHR$(13)THENRETURN
999 GOTO998